package com.nf.service;

import com.nf.dao.TestDao;
import com.nf.entity.Course;
import org.apache.ibatis.io.ResolverUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class TestServiceIml implements TestService {
    private static final int PER_PAGE_SIZE = 10;

    @Autowired
    private TestDao testDao;

    //返回总行数
    @Override
    public int getCountRow() {
        return testDao.getCountRow();
    }

    //返回当前页的内容
    @Override
    public List<Course> getSelectPageCourse(int currentPage) {
        RowBounds rowBounds =  new RowBounds((currentPage-1)*PER_PAGE_SIZE,PER_PAGE_SIZE);
        return testDao.getSelectPageCourse(rowBounds);
    }

    //返回多少页
    @Override
    public int getPageSize() {
        return (getCountRow()+PER_PAGE_SIZE-1)/PER_PAGE_SIZE;
    }
}
